package com.atguigu.tingshu.comment.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/***
 * 评论审核的消息队列配置
 */
@Configuration
public class RabbitCommentConfig {

    /**
     * 交换机
     * @return
     */
    @Bean("commentExchange")
    public Exchange commentExchange(){
        return ExchangeBuilder.directExchange("comment_exchange").build();
    }

    /**
     * 队列
     * @return
     */
    @Bean("commentQueue")
    public Queue commentQueue(){
        return QueueBuilder.durable("comment_queue").build();
    }

    /**
     * 绑定
     * @param commentExchange
     * @param commentQueue
     * @return
     */
    @Bean
    public Binding commentQueueBinding(@Qualifier("commentExchange") Exchange commentExchange,
                                       @Qualifier("commentQueue") Queue commentQueue){
        return BindingBuilder.bind(commentQueue).to(commentExchange).with("track.comment").noargs();
    }
}
